from django.db import models
import datetime
import pytz
from django.core.exceptions import ValidationError, ObjectDoesNotExist

# Create your models here.
class Tema(models.Model):
    titulo = models.CharField(max_length=255)
    area = models.CharField(max_length = 255)
    descripcion = models.TextField()
    autor = models.CharField(max_length = 255)
    uai = models.CharField(max_length = 255)
    academico = models.CharField(max_length=255)
    fecha = models.DateTimeField(null=True, blank=True)
    def save(self):
        self.fecha = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
        super(Tema,self).save()
    def __unicode__(self):
        return self.titulo

class Voto(models.Model):
    na = models.CharField(max_length=255,unique=True)
    tema = models.ForeignKey('Tema')
    fecha = models.DateTimeField()
    def save(self):
        self.fecha = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
        super(Voto,self).save()

class VN(models.Model):
    na = models.CharField(max_length=255)
    tema = models.ForeignKey('Tema')
    area = models.CharField(max_length=255)
    uai = models.CharField(max_length = 255)
    fecha = models.DateTimeField()
    class Meta:
        unique_together = ('na','area')
    def save(self):
        self.area = self.tema.area
        self.fecha = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
        super(VN,self).save()